<template>
	<div @click="refreshCode">
		<s-identify :identifyCode="identifyCode"></s-identify>
	</div>
</template>
<script>
export default {
  name: 'app',
  data () {
    return {
      identifyCodes: 'abcdefghijklmnopqrstvuwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ1234567890',
      identifyCode: ''
    }
  },
  methods: {
    // 生成一个随机数
    randomNum (min, max) {
      return Math.floor(Math.random() * (max - min) + min)
    },
    refreshCode () {
      this.identifyCode = ''
      this.makeCode(this.identifyCodes, 4)
      console.log(this.identifyCode)
    },
    makeCode (o, l) {
      for (let i = 0; i < l; i++) {
        this.identifyCode += this.identifyCodes[this.randomNum(0, this.identifyCodes.length)]
      }
      window.localStorage.setItem('codes', this.identifyCode)
    }
  },
  mounted () {
    this.identifyCode = ''
    this.makeCode(this.identifyCodes, 4)
  }
}
</script>